//
// Description: 875. 爱吃香蕉的珂珂
// Created by Loading on 2022/6/11.
//

#include <bits/stdc++.h>

using namespace std;

int minEatingSpeed(vector<int> &piles, int h) {
    // check函数，判断当前值是否符合要求
    auto check = [&](int x) {
        int res = 0;
        for (auto &pile : piles) {
            res += (pile - 1) / x + 1;
        }

        return res <= h;
    };

    // 二分查找最小值
    int l = 1, r = 1e9;
    while (l < r) {
        int mid = l + (r - l) / 2;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    return l;
}

int main() {
    vector<int> piles = {30, 11, 23, 4, 20};
    int h = 5;

    auto res = minEatingSpeed(piles, h);

    cout << res << endl;

    return 0;
}